$(document).ready(function () {
    //暂存是的url
    var callUrl = null;
    //树节点ID
    var treeNodeId = '';
    //表格查询条件
    var gridCondition = '';
    //查询条件默认值
    var obj = {
        COMPONENTNAME: '1',
        INITVALUE: '0',
        COLUMNWIDTH: '200',
        WIDTH: '0.5'
    };
    //查询结果默认值
    var resultObj = {
        COLWIDTH: '100'
    };
    var me = $(this);
    //控件名称集合
    var component_name_list = [{value:'',text:''},{value: 1, text: "文本框"}, {value: 2, text: "区域文本框"}, {value: 3, text: "下拉框"}, {
        value: 4,
        text: "复选框"
    }, {value: 5, text: "日期型"}, {value: 6, text: "日期时间型"}, {value: 6, text: "数字编辑器"},{value: 7, text: "树形下拉"}];
    //合计的集合
    var totalList = [{value: '', text: ""},{value: 1, text: "汇总"}, {value: 2, text: "总记录"}, {value: 3, text: "最大值"}, {value: 4, text: "最小值"}];
    //图形坐标集合
    var coordinateList = [{value: 1, text: "X"}, {value: 2, text: "Y"}];
    //初始化splitter
    $('#splitter').jqxSplitter({
        width: '100%',
        height: '100%',
        panels: [{size: '20%', min: 150}, {size: '80%', min: 250}]
    });
    $('.jqx-splitter-splitbar-vertical').css('border', 'none');

    /* VUE -- 绑定到查询条件区域表单，ID为queryForm */
    var queryConditions = new Vue({
        el: '#mainForm',
        data: {
            myParams: {}
        }
    });
    var sqlFormVue = new Vue({
        el: '#sqlForm',
        data: {
            myParams: {}
        }
    });

    // 设置查询按钮点击次数
    var queryTime = 0;
    //存储主页面点击的行信息
    var curRow = {};

    /********************表格的初始化操作在此进行 ---- 实例化Grid ************************/
    var grid = $("#conditionGrid").bootstrapTable({
        columns: [{
            checkbox: true
        },
            {
                halign: 'center',
                align: 'center',
                title: '编号',
                field: 'NO',
                formatter: function (value, row, index) {
                    row.index = index + 1;
                    row.SEQUENCE = index;
                    return index + 1;
                }
            }, {
                field: 'FIELDNAME',
                halign: 'center',
                title: '字段名',
                visible: true
            }, {
                field: 'COMPONENTNAME',
                halign: 'center',
                title: '控件名',
                sortable: true,
                formatter: function (value, row, index) {
                    for (var i = 0; i < component_name_list.length; i++) {
                        if (component_name_list[i].value == value) {
                            return component_name_list[i].text;
                        }
                    }
                }
            }, {
                field: 'INITVALUE',
                halign: 'center',
                title: '初始值',
                sortable: true
            }, {
                field: 'REPLACEFIELD',
                halign: 'center',
                title: '替换字',
                sortable: true
            }, {
                field: 'COLUMNWIDTH',
                halign: 'center',
                title: '宽度',
                sortable: true
            }, {
                field: 'WIDTH',
                halign: 'center',
                title: '宽(%)',
                sortable: true
            }, {
                field: 'DEFAULTVALUE',
                halign: 'center',
                title: '默认值',
                sortable: true
            }, {
                field: 'ALLOWLANK',
                halign: 'center',
                title: '是否必填',
                sortable: true
            }],

        sortable: true,//是否可以排序，每一列都可以进行指定
        url: "../../../../api/baseCommonqueryController/listCommonQueryConditions",//加载时调用的后台连接
        undefinedText: '',//字段值为undefine时显示的内容
        showRefresh: false,//是否显示刷新按钮
        showColumns: false,//是否显示列头
        striped: true,//是否显示表格线
        exportDataType: "all", //导出的数据类型
        exportTypes: ['excel'],//导出文件类型
        iconSize: "outline",//icon图标的显示方式
        toolbar: "#grdToolbar",//绑定表格的操作栏，就是新增、修改、删除按钮所在div的ID
        icons: {
            refresh: "glyphicon-repeat",
            toggle: "glyphicon-list-alt",
            columns: "glyphicon-list"
        },
        clickToSelect: false,
        sidePagination: "server", // 表示分页时进行服务端请求
        method: 'post',//请求方法[post/get]
        dataField: 'data',
        singleSelect: true,
        pageNumber: 1,//页面分页的初始页码
        pageSize: 100,//每页显示数量(暂定每页10条，请暂勿修改，保持统一)
        pageList: [5, 10, 25, 50, 100],//每页显示的可选数量
        queryParamsType: "undefined",

        //查询参数配置
        queryParams: function (params) {
            var pIndex, myTotal;
            if (queryTime === 0) {
                pIndex = 1;
                myTotal = -1;
                queryTime++;
            }
            else {
                pIndex = params.pageNumber;
                myTotal = this.totalRows;
            }

            return {
                limit: params.pageSize,
                page: pIndex,
                allcount: myTotal,
                data: {treeNodeId: gridCondition},
                sortName: params.sortName,
                sortOrder: params.sortOrder
            }
        },

        //排序事件
        onSort: function (name, order) {
            grid.queryData();
        },
        onClickRow: function (row, $element) {
            curRow = row;
        },
        onClickCell: function (field, value, row, $element) {
            if (field == 'FIELDNAME') {
                $element.editable({
                    type: "text",                //编辑框的类型。支持text|textarea|select|date|checklist等
                    disabled: false,             //是否禁用编辑
                    emptytext: "",          //空值的默认文本
                    mode: "inline",
                    validate: function (result) {
                        if (!$.trim(result)) {
                            return;
                        }
                        var list = grid.bootstrapTable('getData');
                        var i = 1;
                        if (list) {
                            i = list.length;
                            for (var n = 0; n < i; n++) {

                                var item = list[n];
                                if (row.index - 1 != n) {
                                    if (item.FIELDNAME == result) {
                                        return layer.alert(result + "已存在", {icon: 5});
                                    }
                                }
                            }
                        }
                        row.FIELDNAME = result;
                        if (row.index == i) {
                            var itemData = deepClone(obj);
                            grid.bootstrapTable('append', itemData);
                        }
                    }
                });
            }
            if (field == 'COMPONENTNAME') {
                $element.editable({
                    type: 'select',//指定弹出的编辑框的类型，可以是文本框、下拉框等
                    source: component_name_list,
                    disabled: false,           //是否禁用编辑
                    emptytext: '',       //空值的默认文本
                    mode: "inline",
                    validate: function (result) {
                        row.COMPONENTNAME = result;
                    }
                });
            }
            if (field == 'INITVALUE') {
                $element.editable({
                    type: "text",                //编辑框的类型。支持text|textarea|select|date|checklist等
                    disabled: false,             //是否禁用编辑
                    emptytext: "",          //空值的默认文本
                    mode: "inline",
                    validate: function (result) {
                        row.INITVALUE = result;
                    }
                });
            }
            if (field == 'REPLACEFIELD') {
                $element.editable({
                    type: "text",                //编辑框的类型。支持text|textarea|select|date|checklist等
                    disabled: false,             //是否禁用编辑
                    emptytext: "",          //空值的默认文本
                    mode: "inline",
                    validate: function (result) {
                        if (!$.trim(result)) {
                            return;
                        }
                        var list = grid.bootstrapTable('getData');
                        var i = 1;
                        if (list) {
                            i = list.length;
                            for (var n = 0; n < i; n++) {

                                var item = list[n];
                                if (row.index - 1 != n) {
                                    if (item.REPLACEFIELD == result) {
                                        return layer.alert(result + "已存在", {icon: 5});
                                    }
                                }
                            }
                        }
                        row.REPLACEFIELD = result;
                    }
                });
            }
            if (field == 'COLUMNWIDTH') {
                $element.editable({
                    type: "text",                //编辑框的类型。支持text|textarea|select|date|checklist等
                    disabled: false,             //是否禁用编辑
                    emptytext: "",          //空值的默认文本
                    mode: "inline",
                    validate: function (result) {
                        row.COLUMNWIDTH = result;
                    }
                });
            }
            if (field == 'WIDTH') {
                $element.editable({
                    type: "text",                //编辑框的类型。支持text|textarea|select|date|checklist等
                    disabled: false,             //是否禁用编辑
                    emptytext: '',          //空值的默认文本
                    mode: "inline",
                    validate: function (result) {
                        row.WIDTH = result;
                    }
                });
            }
            if (field == 'DEFAULTVALUE') {
                $element.editable({
                    type: "text",                //编辑框的类型。支持text|textarea|select|date|checklist等
                    disabled: false,             //是否禁用编辑
                    emptytext: "",          //空值的默认文本
                    mode: "inline",
                    validate: function (result) {
                        row.DEFAULTVALUE = result;
                    }
                });
            }
            if (field == 'ALLOWLANK') {
                $element.editable({
                    type: "text",                //编辑框的类型。支持text|textarea|select|date|checklist等
                    disabled: false,             //是否禁用编辑
                    emptytext: "",          //空值的默认文本
                    mode: "inline",
                    validate: function (result) {
                        row.ALLOWLANK = result;
                    }
                });
            }
        },
        //数据加载完毕事件
        onLoadSuccess: function (result) {
            // 数据加载完成后处理某些信息

            //点击连接的时候弹出可编辑输入框，便于修改
            //基于控件：bootstrap-editable.js
            //参考博客地址:http://www.cnblogs.com/landeanfen/p/5821192.html
            $("#tableGrid a").click(function () {

            });
        }
    });
    var gridCurRow = {};
    var gridResult = $("#resultGrid").bootstrapTable({
        columns: [{
            checkbox: true
        },
            {
                halign: 'center',
                align: 'center',
                title: '编号',
                field: 'NO',
                formatter: function (value, row, index) {
                    row.index = index + 1;
                    row.SEQUENCE = index;
                    return index + 1;
                }
            }, {
                field: 'NAME1',
                halign: 'center',
                title: '列名'
            }, {
                field: 'COLWIDTH',
                halign: 'center',
                title: '列宽'
            }, {
                field: 'ISGROUP',
                halign: 'center',
                title: '合计',
                formatter: function (value, row, index) {
                    for (var i = 0; i < totalList.length; i++) {
                        if (totalList[i].value == value) {
                            return totalList[i].text;
                        }
                    }
                }
            }, {
                field: 'COORDINATE',
                halign: 'center',
                title: '图形坐标',
                formatter: function (value, row, index) {
                    for (var i = 0; i < coordinateList.length; i++) {
                        if (coordinateList[i].value == value) {
                            return coordinateList[i].text;
                        }
                    }
                }
            }, {
                field: 'NEXTQUERY',
                halign: 'center',
                title: '子查询'
            }],

        sortable: true,//是否可以排序，每一列都可以进行指定
        url: "../../../../api/baseCommonqueryController/listCommonQueryResults",//加载时调用的后台连接
        undefinedText: '',//字段值为undefine时显示的内容
        showRefresh: false,//是否显示刷新按钮
        showColumns: false,//是否显示列头
        striped: true,//是否显示表格线
        showExport: false, //是否显示导出按钮
        singleSelect: true,
        //导出时的文件信息配置
        exportOptions: {
            fileName: '模版类型',
            worksheetName: '模版类型'
        },
        exportDataType: "all", //导出的数据类型
        exportTypes: ['excel'],//导出文件类型
        iconSize: "outline",//icon图标的显示方式
        toolbar: "#gridResultToolbar",//绑定表格的操作栏，就是新增、修改、删除按钮所在div的ID
        icons: {
            refresh: "glyphicon-repeat",
            toggle: "glyphicon-list-alt",
            columns: "glyphicon-list"
        },
        clickToSelect: false,
        pagination: true,//是否分页
        sidePagination: "server", // 表示分页时进行服务端请求
        method: 'post',//请求方法[post/get]
        dataField: 'data',
        pageNumber: 1,//页面分页的初始页码
        pageSize: 100,//每页显示数量(暂定每页10条，请暂勿修改，保持统一)
        pageList: [5, 10, 25, 50, 100],//每页显示的可选数量
        queryParamsType: "undefined",

        //查询参数配置
        queryParams: function (params) {
            var pIndex, myTotal;
            if (queryTime === 0) {
                pIndex = 1;
                myTotal = -1;
                queryTime++;
            }
            else {
                pIndex = params.pageNumber;
                myTotal = this.totalRows;
            }

            return {
                limit: params.pageSize,
                page: pIndex,
                allcount: myTotal,
                data: {treeNodeId: gridCondition},
                sortName: params.sortName,
                sortOrder: params.sortOrder
            }
        },

        //排序事件
        onSort: function (name, order) {
            grid.queryData();
        },
        onClickRow: function (row, $element) {
            gridCurRow = row;
        },
        onClickCell: function (field, value, row, $element) {
            if (field == 'NAME1') {
                $element.editable({
                    type: "text",                //编辑框的类型。支持text|textarea|select|date|checklist等
                    disabled: false,             //是否禁用编辑
                    emptytext: "",          //空值的默认文本
                    mode: "inline",
                    validate: function (result) {
                        row.NAME1 = result;
                        var list = gridResult.bootstrapTable('getData');
                        var i = 1;
                        if (list) {
                            i = list.length;
                        }
                        if (row.index == i) {
                            var resultData = deepClone(resultObj);
                            gridResult.bootstrapTable('append', resultData);
                        }
                    }
                });
            }
            if (field == 'COLWIDTH') {
                $element.editable({
                    type: "text",                //编辑框的类型。支持text|textarea|select|date|checklist等
                    disabled: false,             //是否禁用编辑
                    emptytext: "",          //空值的默认文本
                    mode: "inline",
                    validate: function (result) {
                        row.COLWIDTH = result;
                    }
                });
            }
            if (field == 'ISGROUP') {
                $element.editable({
                    type: 'select',//指定弹出的编辑框的类型，可以是文本框、下拉框等
                    source: totalList,
                    disabled: false,           //是否禁用编辑
                    emptytext: '',       //空值的默认文本
                    mode: "inline",
                    validate: function (result) {
                        row.ISGROUP = result;
                    }
                });
            }
            if (field == 'COORDINATE') {
                $element.editable({
                    type: "select",                //编辑框的类型。支持text|textarea|select|date|checklist等
                    source: coordinateList,
                    disabled: false,             //是否禁用编辑
                    emptytext: "",          //空值的默认文本
                    mode: "inline",
                    validate: function (result) {
                        row.COORDINATE = result;
                    }
                });
            }
            if (field == 'NEXTQUERY') {
                $element.editable({
                    type: "text",                //编辑框的类型。支持text|textarea|select|date|checklist等
                    disabled: false,             //是否禁用编辑
                    emptytext: "",          //空值的默认文本
                    mode: "inline",
                    validate: function (result) {
                        row.NEXTQUERY = result;
                    }
                });
            }
        },
        //数据加载完毕事件
        onLoadSuccess: function (result) {
            // 数据加载完成后处理某些信息

            //点击连接的时候弹出可编辑输入框，便于修改
            //基于控件：bootstrap-editable.js
            //参考博客地址:http://www.cnblogs.com/landeanfen/p/5821192.html
            $("#tableGrid a").click(function () {

            });
        }
    });
    $("#resultGrid").parent('div').parent().css('height','395px');
    $("#conditionGrid").parent('div').parent().css('height','395px');

    /********************初始化表单函数 -- 对表格上面的相关按钮就行操作事件绑定*****************/
    /* 数据查询 */
    grid.queryData = function () {
        queryTime = 0;
        this.bootstrapTable('refresh', {
            silent: false
        });
    };
    gridResult.queryData = function () {
        queryTime = 0;
        this.bootstrapTable('refresh', {
            silent: false
        });
    };

    /* 查询按钮点击 */
    $('#btnQuery').click(function () {
        grid.queryData();
    });

    /*重置按钮*/
    $('#resetBtn').click(function () {
        $('#queryForm').find("input")
            .not(':button, :submit, :reset, :hidden')
            .val('')
            .removeAttr('checked')
            .removeAttr('selected');
        queryConditions.myParams = {};
    });
    //树菜单配置项
    var setting = {
        view: {
            selectedMulti: false
        },
        check: {
            enable: false
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        edit: {
            enable: false
        },
        callback: {
            onClick: onClick
        }
    };

    //树菜单数据
    var zNodes = null;

    //获取树菜单数据
    var callContractTempTree = app.callAjaxPostSync("../../../../api/baseCommonqueryController/listCommonQueryTypes", {});
    if (callContractTempTree.success) {
        zNodes = callContractTempTree.data;
    }

    //节点点击事件
    function onClick(event, treeId, treeNode, clickFlag) {
        //节点点击时，根据是否是父节点来判断弹出层的类型
        $('button').attr({"disabled": "disabled"});
        callUrl = null;
        treeNodeId = treeNode.id;
        gridCondition = treeNode.id;
        if (treeNode.id == '0') {
            $('#add').removeAttr("disabled");
            $('#sort').removeAttr("disabled");
            queryConditions.myParams = {
                PARENTID: treeNode.id
            };
            // queryConditions.myParams.PARENTID = treeNode.id;
        } else {
            var result = app.callAjaxPostSync('../../../../api/baseCommonqueryController/getEntityById', {ID: treeNode.id});
            if (result.data) {

                queryConditions.myParams = result.data;
                var sqlObj = {
                    SQLSCRIPT: result.data.SQLSCRIPT
                }
                sqlFormVue.myParams = sqlObj;
            }
            if (result.data.ISLEAF == '1') {
                $('button[id!="add"]').removeAttr("disabled");
                $('#sort').attr({"disabled": "disabled"});
            } else {
                $('button').removeAttr("disabled");
                $('#conditionSort,#resultSort').attr({"disabled": "disabled"});
            }
            $('#saveZan,#cancel').attr({"disabled": "disabled"});
        }
        grid.queryData();
        gridResult.queryData();
    }

    //初始化树菜单
    $.fn.zTree.init($("#commonqueryTree"), setting, zNodes);

    //刷新树菜单
    function refreshTree() {

        //树菜单数据
        var zTreeNodes = null;

        //获取树菜单数据
        var callContractTempTree = app.callAjaxPostSync("../../../../api/baseCommonqueryController/listCommonQueryTypes", {});
        if (callContractTempTree.success) {
            zTreeNodes = callContractTempTree.data;
        }
        //初始化树菜单
        $.fn.zTree.init($("#commonqueryTree"), setting, zTreeNodes);
    }

    //新增节点
    $('#add').click(function () {
        callUrl = callUrl + 'save';

        callUrl = '../../../../api/baseCommonqueryController/save';
        queryConditions.myParams = {
            PARENTID: treeNodeId
        }
        $("button").attr({"disabled": "disabled"});
        $('input').removeAttr("readonly");
        $('#saveZan').removeAttr("disabled");
        $('#copy').attr({"disabled": "disabled"});
        grid.bootstrapTable('removeAll');
        gridResult.bootstrapTable('removeAll');
        for(var i=0;i<2;i++){
            var resultData = deepClone(resultObj);
            gridResult.bootstrapTable('append', resultData);
            var itemDate = deepClone(obj);
            grid.bootstrapTable('append', itemDate);
        }
    });

    //修改节点
    $('#edit').click(function () {
        callUrl = '../../../../api/baseCommonqueryController/update';
        $('input').removeAttr("readonly");
        $('#saveZan,#cancel,#copy').removeAttr("disabled");
    });

    //作废按钮
    $('#remove').click(function () {
        var result = app.callAjaxPostSync('../../../../api/baseCommonqueryController/delete', {ID: gridCondition});
        if (result.success) {
            layer.alert('作废成功');
            refreshTree();
            $('button').attr({"disabled": "disabled"});
        }
    });

    //撤销
    $('#cancel').click(function () {
        var result = app.callAjaxPostSync('../../../../api/baseCommonqueryController/getEntityById', {ID: gridCondition});
        if (result.data) {
            refreshTree();
            queryConditions.myParams = result.data;
            var sqlObj = {
                SQLSCRIPT: result.data.SQLSCRIPT
            }
            sqlFormVue.myParams = sqlObj;
        }
        grid.queryData();
        gridResult.queryData();
    });

    //排序
    $('#sort').click(function () {
        layer.open({
            type: 2,//弹出层类型
            title: '查询模板排序',//弹出层标题
            shadeClose: true,
            shade: 0.5,//透明度
            area: ['70%', '93%'],//大小
            shift: 5,
            content: ['commonQuerySort.html?_dc=' + Math.random() + "&ID=" + treeNodeId, 'yes'],
            end: function () {

                refreshTree();
            }
        });
    });

    //条件排序
    $('#conditionSort').click(function () {
        layer.open({
            type: 2,//弹出层类型
            title: '查询模板条件排序',//弹出层标题
            shadeClose: true,
            shade: 0.5,//透明度
            area: ['70%', '93%'],//大小
            shift: 5,
            content: ['commonQueryConditionSort.html?_dc=' + Math.random() + "&ID=" + treeNodeId, 'yes'],
            end: function () {
                grid.queryData();
            }
        });
    });

    //结果排序
    $('#resultSort').click(function () {
        layer.open({
            type: 2,//弹出层类型
            title: '查询模板结果排序',//弹出层标题
            shadeClose: true,
            shade: 0.5,//透明度
            area: ['70%', '93%'],//大小
            shift: 5,
            content: ['commonQueryResultSort.html?_dc=' + Math.random() + "&ID=" + treeNodeId, 'yes'],
            end: function () {
                gridResult.queryData();
            }
        });
    });

    //暂存按钮
    $('#saveZan').click(function () {
        if (queryConditions.myParams.PARENTID && queryConditions.myParams.PARENTID != '') {
            var isValid = $("#mainForm").valid();
            if (isValid) {

                var obj = deepClone(queryConditions.myParams);
                obj.ISLEAF = obj.ISLEAF ? '1' : '0';
                var conditionList = grid.bootstrapTable('getData');
                var resultList = gridResult.bootstrapTable('getData');
                obj.SQLSCRIPT = sqlFormVue.myParams.SQLSCRIPT;
                var code = obj.CODE;
                if (callUrl == '../../../../api/baseCommonqueryController/update'){
                    obj.ID=gridCondition;
                }
                var countResult = app.callAjaxPostSync('../../../../api/baseCommonqueryController/checkIsExist', {
                    CODE: code,
                    ID: obj.ID
                });
                if (!countResult.success) {
                    layer.alert(countResult.message, {icon: 5});
                    return;
                }
                app.callAjaxPost(callUrl, {
                    baseCommonquery: obj,
                    baseCommonqueryconditions: conditionList,
                    baseCommonqueryresults: resultList
                }, function (result) {
                    if (callUrl != '../../../../api/baseCommonqueryController/update') {
                        callUrl = '../../../../api/baseCommonqueryController/update';
                        gridCondition = result.data.ID;
                        grid.queryData();
                        gridResult.queryData();
                    }
                    layer.alert(result.message, {icon: 1});
                    refreshTree();
                }, this);
            }
        }
    });

    //复制按钮
    $('#copy').click(function () {
        layer.prompt({
            formType: 0,
            title: '请输入目标查询编码：'
        }, function (value, index, elem) {
            app.callAjaxPost("../../../../api/baseCommonqueryController/copy", {
                treeNodeId: treeNodeId,
                targetId: value
            }, function (result) {
                if (result.success) {
                    layer.alert('复制成功', {icon: 6});
                    layer.closeAll();
                    refreshTree();
                } else {
                    layer.alert(result.message, {icon: 5});
                }
            });
        });
    });
    //预览按钮
    $('#reView').click(function () {
        var headData = deepClone(queryConditions.myParams);
        var conditionList = grid.bootstrapTable('getData');
        var resultList = gridResult.bootstrapTable('getData');
        var list=[];
        var headList=[];
        headData.SQLSCRIPT=sqlFormVue.myParams.SQLSCRIPT;
        for( var i=0;i<resultList.length;i++){
            var resultItem=resultList[i];
            if($.trim(resultItem.NAME1)){
                list.push(resultItem);
            }
        }
        for( var n=0;n<conditionList.length;n++){
            var conditionItem=conditionList[n];
            if($.trim(conditionItem.FIELDNAME)){
                headList.push(conditionItem);
            }
        }
        var data = {
            baseCommonquery: headData,
            baseCommonqueryconditions: headList,
            baseCommonqueryresults: list
        };
        var dataStr = JSON.stringify(data);
        localStorage.setItem("templeteReviewData", dataStr);

        openNewTab('../system/commonquery/templeteReview.html', '模板预览');
    });
    $('#gridDelete').click(function () {
        var gridList = grid.bootstrapTable('getSelections');
        if (gridList && gridList.length > 0) {
            var mtConfirm = layer.confirm('您确定要删除么？', {
                    btn: ['是', '否'], //按钮
                    shade: false //不显示遮罩（默认使用该配置）
                }, function (index) {
                    var obj = gridList[0];
                    var allList = grid.bootstrapTable('getData');
                    if ($.trim(obj.ID)) {
                        app.callAjaxPostSync('../../../../api/baseCommonqueryController/deleteCondition', obj);
                    }
                    allList.splice(obj.index - 1, 1);
                    grid.bootstrapTable("load", allList);
                layer.close(index);
                }
            );
        }
    });
    $('#gridResultDelete').click(function () {
        var gridList = gridResult.bootstrapTable('getSelections');
        if (gridList && gridList.length > 0) {
            var mtConfirm = layer.confirm('您确定要删除么？', {
                    btn: ['是', '否'], //按钮
                    shade: false //不显示遮罩（默认使用该配置）
                }, function (index) {
                    var obj = gridList[0];
                    var allList = gridResult.bootstrapTable('getData');

                    if ($.trim(obj.ID)) {
                        app.callAjaxPostSync('../../../../api/baseCommonqueryController/deleteResult', obj);
                    }
                    allList.splice(obj.index - 1, 1);
                    gridResult.bootstrapTable("load", allList);
                    layer.close(index);
                }
            );
        }
    });

//深度克隆
    function deepClone(obj) {
        var result, oClass = isClass(obj);
        //确定result的类型
        if (oClass === "Object") {
            result = {};
        } else if (oClass === "Array") {
            result = [];
        } else {
            return obj;
        }
        for (key in obj) {
            var copy = obj[key];
            if (isClass(copy) == "Object") {
                result[key] = arguments.callee(copy);//递归调用
            } else if (isClass(copy) == "Array") {
                result[key] = arguments.callee(copy);
            } else {
                result[key] = obj[key];
            }
        }
        return result;
    }

//返回传递给他的任意对象的类
    function isClass(o) {
        if (o === null) return "Null";
        if (o === undefined) return "Undefined";
        return Object.prototype.toString.call(o).slice(8, -1);
    }
});
